package com.yycx.msg.provider.handler;

import com.yycx.common.base.handler.SmsSendHandler;
import com.yycx.msg.client.model.SmsMessage;
import com.yycx.msg.provider.sms.SmsSender;
import com.yycx.msg.provider.service.impl.AliyunSmsSenderImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author flyme
 * @date 2019/8/21 15:38
 */
@Component("aliSmsHandler")
public class AliSmsHandler implements SmsSendHandler {

    @Autowired
    private SmsSender smsSender;

    @Override
    public void send(String mobile, Integer code, String areaCode) {
        SmsMessage smsMessage = new SmsMessage();
        smsMessage.setPhoneNum(mobile);
        smsMessage.add("code", code);
        smsMessage.setCode(code.toString());
        smsSender.sendSmsCode(smsMessage);
    }

    @Override
    public void sendSms(String mobile, String tplCode, Map<String, Object> params) {
        SmsMessage smsMessage = new SmsMessage();
        smsMessage.setPhoneNum(mobile);
        smsMessage.setTplCode(tplCode);
        smsMessage.setTplParams(params);
        smsSender.sendSms(smsMessage);
    }

    public static void main(String[] args) {
        AliyunSmsSenderImpl aliyunSmsSender = new AliyunSmsSenderImpl();
        SmsMessage smsNotify = new SmsMessage();
        smsNotify.setPhoneNum("18739941307");
        smsNotify.setSignName("玩了么商城");
        smsNotify.setTplCode("SMS_174814144");
        smsNotify.add("code", "1254587");
        aliyunSmsSender.send(smsNotify);
    }
}
